<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>sr</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="sqrt.html" title="sqrt" />
    <link rel="next" href="statevar.html" title="statevar" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">sr</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="sqrt.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="statevar.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="sr"></a>
      <div class="titlepage"></div>
      <a id="IndexSr" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">sr</span>
        </h2>
        <p>sr — 
      Sets the audio sampling rate.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp151444832"></a>
        <h2>Description</h2>
        <p>
      These statements are global value <a class="link" href="assign.html" title="="><em class="citetitle">assignments</em></a>, made
      at the beginning of an orchestra, before any instrument block is
      defined. Their function is to set certain <a class="link" href="OrchKvar.html#VariableTypes" title="Table 3. Types of Variables"><em class="citetitle">reserved symbol
      variables</em></a> that are required for
      performance. Once set, these reserved symbols can be used in
      expressions anywhere in the orchestra. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp151510960"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>sr</strong></span> = iarg</pre>
      </div>
      <div class="refsect1">
        <a id="idp151512944"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>sr</em></span>  = (optional) -- set sampling rate to <span class="emphasis"><em>iarg</em></span> samples per second per channel. The default value is 44100.
    </p>
        <p>
      In addition, any <a class="link" href="OrchKvar.html#GlobalVariables"><em class="citetitle">global variable</em></a> can be initialized by an <span class="emphasis"><em>init-time assignment</em></span> anywhere before the first <a class="link" href="instr.html" title="instr"><em class="citetitle">instr statement</em></a>.  All of the above assignments are run as instrument 0 (i-pass only) at the start of real performance.
    </p>
        <p>
      Beginning with Csound version 3.46, <span class="emphasis"><em>sr</em></span> may be omitted. The sample rate will be calculated from <a class="link" href="kr.html" title="kr"><em class="citetitle">kr</em></a> and <a class="link" href="ksmps.html" title="ksmps"><em class="citetitle">ksmps</em></a>, but this must evaluate to an integer. If none of these global values is defined, the sample rate will default to 44100. You will usually want to use a value that your soundcard supports, like 44100 or 48000, otherwise, the audio generated by csound may be unplayable, or you will get an error if you attempt to run in real-time. You may naturally use a sample rate like 96000, for off-line rendering even if your soundcard doesn't support it. Csound will generate a valid file that can be played on capable systems.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp151521184"></a>
        <h2>Examples</h2>
        <p>
      </p>
        <div class="informalexample">
          <pre class="programlisting">
<span class="ohdr">sr</span> <span class="op">=</span> 10000
<span class="ohdr">kr</span> <span class="op">=</span> 500
<span class="ohdr">ksmps</span> <span class="op">=</span> 20
gi1 <span class="op">=</span> <span class="ohdr">sr</span><span class="op">/</span>2.
ga <span class="opc">init</span> 0
itranspose <span class="op">=</span> <span class="opc">octpch</span>(.0l)</pre>
        </div>
        <p>
    </p>
        <p>
      Here is another example of the sr opcode. It uses the file <a class="ulink" href="examples/sr.csd" target="_top"><em class="citetitle">sr.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp151532240"></a>
          <p class="title">
            <strong>Example 840. Example of the sr opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac  <span class="comment">;;;realtime audio out</span>
<span class="comment">; -iadc    ;;;uncomment -iadc if real audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o sr.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1	<span class="comment">;use sr to find maximum harmonics</span>

ihar	<span class="op">=</span> <span class="opc">int</span>(<span class="ohdr">sr</span><span class="op">/</span>2<span class="op">/</span>p4)		<span class="comment">; maximum possible number of harmonics w/o aliasing</span>
<span class="opc">prints</span>  "maximum number of harmonics <span class="op">=</span> <span class="op">%</span>d \\n", ihar
kenv	<span class="opc">linen</span> .5, 1, p3, .2	<span class="comment">; envelope</span>
asig	<span class="opc">buzz</span>  kenv, p4, ihar, 1
	<span class="opc">outs</span>  asig, asig

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1 0 4096 10 1	<span class="comment">;sine wave</span>

<span class="stamnt">i</span> 1 0 3 100	<span class="comment">;different frequencies</span>
<span class="stamnt">i</span> 1 + 3 1000
<span class="stamnt">i</span> 1 + 3 10000
<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
            Its output should include lines like this:
      </p>
        <pre class="screen">
maximum number of harmonics = 240 
maximum number of harmonics = 24 
maximum number of harmonics = 2 
      </pre>
        <p>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp151537312"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="kr.html" title="kr"><em class="citetitle">kr</em></a>,
      <a class="link" href="ksmps.html" title="ksmps"><em class="citetitle">ksmps</em></a>,
      <a class="link" href="nchnls.html" title="nchnls"><em class="citetitle">nchnls</em></a>,
      <a class="link" href="nchnls_i.html" title="nchnls_i"><em class="citetitle">nchnls_i</em></a>.
    </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="sqrt.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="statevar.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">sqrt </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> statevar</td>
        </tr>
      </table>
    </div>
  </body>
</html>
